
public class Lista implements Structura {
	protected int[] lista;
	private static int poz;//poz. curenta in vector
	private static int lungimeMaxima;//lung. max. a listei.
	public Lista()
	{
		poz=0;
		lungimeMaxima=10;
		lista=new int[10];
	}//constructor de initializare
	public Lista(int dimensiune)
	{
		poz=0;
		lungimeMaxima=dimensiune;
		lista=new int[dimensiune];
	}

	private void setLista(int[] l)
	{
		int n=l.length;
	    for(int i=0;i<n;i++)
	    {
	    	this.lista[i]=l[i];
	    }
	    
	}
	
	public void adauga(int elem)//pt. adaugarea unui element dat ca parametru in spatele listei;
	{
		if(poz<lungimeMaxima)
		{
		lista[poz]=elem;
		poz=poz+1;
		}
		else
		{
			System.err.println("[Error]List is full, no more elements can be accepted "+elem);
		}
		
	}
	public void sterge(int elem)//pt. eliminarea unui element dat ca parametru din vector;
	{
		int i=0;
		int[] aux=new int[lungimeMaxima];
		int pozAux=0;
		int nrAparitii=0;
		while(i<poz)
		{
			if(this.lista[i]!=elem)
			{
			  	aux[pozAux]=this.lista[i];
			  	pozAux++;
			}
			else
			{
				nrAparitii++;
			}
			i++;
		}
		this.setLista(aux);
		poz=poz-nrAparitii;
		
	}
	public void inserareLaIndice(int indice, int elem)//returneaza valoarea elementului cu un anumit indice dat
	{
		if((indice>=0)&&(indice<lungimeMaxima))
		{
			int [] aux=new int[lungimeMaxima];
			int i=0;
            for(i=0;i<indice;i++)
            {
            	aux[i]=this.lista[i];
            }
            aux[i]=elem;
            i++;
            for(int j=i;j<poz;j++)
            {
            	aux[i]=this.lista[j];
            }
            System.out.println("j"+aux.length+" "+indice);
            for(int k=0;k<aux.length;k++)
            {
            	System.out.println(aux[k]);
            }
            if(indice>=poz)
            {
            poz=aux.length;
            }
            this.setLista(aux);
		}
		else
		{
			System.err.println("[Eroare]Index invalid in list");
		}
	}
	public void afiseaza()//afiseaza lista
	{
		if(poz>0)
		{
		System.out.print("The List:(");
		for(int i=0;i<poz-1;i++)
		{
			System.out.print(this.lista[i]+",");
		}
		System.out.println(this.lista[poz-1]+")");
		}
		else
		{
			System.out.println("The list is null");
		}
	}
	

}
